package redis

import (
	"fmt"
	"myblogs/app/variable"

	"github.com/go-redis/redis"
)

var client *redis.Client

func InitRedis() {
	addr := fmt.Sprintf("%s:%d", variable.RedisHost, variable.RedisPort)
	client = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: variable.RedisPass, // 密码
		DB:       0,                  // 数据库
		PoolSize: 20,                 // 连接池大小
	})
	_, err := client.Ping().Result()
	if err != nil {
		panic(err)
	}
}

func RedisClient() *redis.Client {
	return client
}
